home *** CD-ROM | disk | FTP | other *** search
/ CD/PC Actual 76 / DVD Actual 1 Marzo 2003.iso / Trial / TurboCAD 7.1 Pro / Data.Cab / F25101_ToolList.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-11-10  |  5.9 KB  |  249 lines

  1. // ToolList.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "InsTool.h"
  6. #include "ToolList.h"
  7. #include "TDialog.h"
  8.  
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14.  
  15. /////////////////////////////////////////////////////////////////////////////
  16. // ToolList
  17.  
  18. CToolList::CToolList()
  19. {
  20. //    EnableAutomation();
  21. }
  22.  
  23. CToolList::~CToolList()
  24. {
  25. }
  26.  
  27. void CToolList::OnFinalRelease()
  28. {
  29.     // When the last reference for an automation object is released
  30.     // OnFinalRelease is called.  The base class will automatically
  31.     // deletes the object.  Add additional cleanup required for your
  32.     // object before calling the base class.
  33.  
  34.     CListBox::OnFinalRelease();
  35. }
  36.  
  37.  
  38. BEGIN_MESSAGE_MAP(CToolList, CListBox)
  39.     //{{AFX_MSG_MAP(CToolList)
  40.     ON_WM_LBUTTONDOWN()
  41.     ON_WM_LBUTTONUP()
  42.     ON_WM_MOUSEMOVE()
  43.     ON_CONTROL_REFLECT(LBN_SELCHANGE, OnSelchange)
  44.     //}}AFX_MSG_MAP
  45. END_MESSAGE_MAP()
  46.  
  47. /////////////////////////////////////////////////////////////////////////////
  48. // ToolList message handlers
  49.  
  50. void CToolList::RefreshFileList(CString path)
  51. {
  52.     struct _finddata_t c_file;
  53.     long hFile;
  54.     hFile = 0;
  55. //    int i = _chdir("c:\\SYMBOLS");  // the directory that contains symbols. 
  56.     int i = _chdir(path);  // the directory that contains symbols. 
  57.     ResetContent();
  58.     m_cstrCurSelected = "";
  59.     /* Find first .c file in current directory */
  60.     if (i == 0)
  61.     {
  62.         if( (hFile = _findfirst( "*.tcw", &c_file )) != -1L )//# Non-localizable string#
  63.         {
  64.             /* Find the rest of the .c files */
  65.             AddString(c_file.name); //add first file to the list
  66.   
  67.             while( _findnext( hFile, &c_file ) == 0 )            
  68.             {
  69.                 AddString(c_file.name);
  70.                     
  71.             }
  72.             _findclose( hFile );  
  73.         }
  74. //        else
  75. //            MessageBox("Selected directory doesn't contain *.tcw files", "Warning", MB_OK);
  76.     
  77.     }
  78.  
  79. }
  80.  
  81.  
  82.  
  83. void CToolList::OnLButtonDown(UINT nFlags, CPoint point) 
  84. {
  85.     // TODO: Add your message handler code here and/or call default
  86.     CListBox::OnLButtonDown(nFlags, point);
  87.     BOOL ret;
  88.  
  89.     m_LB_DOWNpoint.x = point.x;
  90.     m_LB_DOWNpoint.y = point.y;
  91.     
  92.     CString cstrSelected = "";
  93.     CListBox *pList = (CListBox *) (GetParent()->GetDlgItem(IDC_LIST1));
  94.  
  95.     UINT index = ItemFromPoint(point, ret);
  96.     if (ret == FALSE)
  97.     {
  98.         m_drag = TRUE; 
  99.         GetText(index, cstrSelected);
  100.     }
  101.     if (m_cstrCurSelected != cstrSelected && cstrSelected != "") // check if the current selection is changed
  102.     {
  103.         BeginWaitCursor();    
  104.         CViewWnd *pView = (CViewWnd *) (((CTDialog*)GetParent())->GetDlgItem(IDC_PREVIEW));
  105.         pView->ClearAll();
  106.         int index = pList->GetCurSel();
  107.         
  108.         BOOL a = FALSE;
  109.  
  110.         a = pView->CreatePreview();
  111.         if(a == FALSE)
  112.             return;
  113.         
  114.         a = FALSE;
  115.         a = pView->DoPreview();
  116.         if (a = FALSE)
  117.         {
  118.             CString szMess;
  119.             CString szCap;
  120.             szMess.LoadString(IDS_STRING105);
  121.             szCap.LoadString(IDS_STRING106);
  122.             //MessageBox("The drawing have Brush styles or Line styles different from default. This sample can't work with such files", "ERROR!", MB_OK);//# Localizable string#
  123.             MessageBox(LPCTSTR(szMess),LPCTSTR(szCap), MB_OK);
  124.             pList->DeleteString(index);
  125.         }
  126.         m_cstrCurSelected = cstrSelected;
  127.         pView->Invalidate();
  128.         EndWaitCursor();
  129.     }
  130.  
  131.  
  132. }
  133.  
  134. void CToolList::OnLButtonUp(UINT nFlags, CPoint point) 
  135. {
  136.     // TODO: Add your message handler code here and/or call default
  137.     
  138.     CListBox::OnLButtonUp(nFlags, point);
  139.     m_drag = FALSE;
  140.  
  141.     CPoint Pt = point;
  142.     ClientToScreen(&Pt);
  143.     CWnd *pClickWNd = WindowFromPoint(Pt);
  144.         
  145.     if(pClickWNd && pClickWNd != this)
  146.     {
  147.         pClickWNd->ScreenToClient(&Pt);
  148.         pClickWNd->PostMessage(WM_LBUTTONUP, nFlags, MAKELONG(Pt.x, Pt.y));
  149.         SetCursor(m_OldCursor);
  150.         ShowCursor(TRUE);
  151.         return;
  152.                             
  153.     }
  154.     else
  155.     {
  156.         SetCursor(m_OldCursor);
  157.         ShowCursor(TRUE);
  158. //        ((CTDialog*)GetParent())->DisconectEvents();
  159.  
  160.     }
  161.  
  162. }
  163.  
  164. void CToolList::OnMouseMove(UINT nFlags, CPoint point) 
  165. {
  166.     // TODO: Add your message handler code here and/or call default
  167.     
  168.     if(nFlags & MK_LBUTTON)
  169.     {
  170.         
  171.         int dx = m_LB_DOWNpoint.x - point.x;
  172.         int dy = m_LB_DOWNpoint.y - point.y;
  173.         CPoint Pt = point;
  174.  
  175.         if((abs(dx) > 1 || abs(dy) > 1) && m_drag)
  176.         {
  177. // if dragging
  178.             if (((CTDialog*)GetParent())->m_dwEventConnection == 0)
  179.             {
  180.                 ((CTDialog*)GetParent())->ConnectEvents();
  181.             }
  182.  
  183.                 m_OldCursor = GetCursor();
  184.                 m_NewCursor = LoadCursor(AfxGetInstanceHandle( ), MAKEINTRESOURCE(IDC_CURSOR1));
  185.                 SetCursor(m_NewCursor);
  186.                 ShowCursor(TRUE);
  187.                 m_drag = FALSE;
  188.                 m_LB_DOWNpoint.x = -1;
  189.                 m_LB_DOWNpoint.y = -1;
  190.                 ((CTDialog*)GetParent())->m_FirstClick = TRUE;
  191.                 return;
  192.                         
  193.         }
  194.  
  195.         ClientToScreen(&Pt);
  196.         CWnd *pClickWNd = WindowFromPoint(Pt);
  197.  
  198.         if(pClickWNd && pClickWNd != this)
  199.         {
  200.             pClickWNd->ScreenToClient(&Pt);
  201.             pClickWNd->PostMessage(WM_MOUSEMOVE, nFlags, MAKELONG(Pt.x, Pt.y));
  202.         }
  203.  
  204.     }
  205.  
  206. }
  207.  
  208. void CToolList::OnSelchange() 
  209.  
  210. {
  211.     // TODO: Add your control notification handler code here
  212.  
  213.     CListBox *pList = (CListBox *) (GetParent()->GetDlgItem(IDC_LIST1));
  214.     int index = pList->GetCurSel();
  215.     CString cstrSelected;
  216.     HCURSOR hOC = ::SetCursor(::LoadCursor(NULL,IDC_WAIT));
  217.  
  218.     pList->GetText(index, cstrSelected);
  219.     
  220.     if (m_cstrCurSelected != cstrSelected && cstrSelected != "")
  221.     {
  222.         CViewWnd *pView = (CViewWnd *) (((CTDialog*)GetParent())->GetDlgItem(IDC_PREVIEW));
  223.         pView->ClearAll();
  224.         
  225.         BOOL a = FALSE;
  226.  
  227.         a = pView->CreatePreview();
  228.         if(a == FALSE)
  229.             return;
  230.         
  231.         a = FALSE;
  232.         a = pView->DoPreview();
  233.         if (a = FALSE)
  234.         {
  235.             CString szMess;
  236.             CString szCap;
  237.             szMess.LoadString(IDS_STRING105);
  238.             szCap.LoadString(IDS_STRING106);
  239.             //MessageBox("The drawing have Brush styles or Line styles different from default. This sample can't work with such files", "ERROR!", MB_OK);//# Localizable string#
  240.             MessageBox(LPCTSTR(szMess),LPCTSTR(szCap), MB_OK);
  241.             pList->DeleteString(index);
  242.         }
  243.         m_cstrCurSelected = cstrSelected;
  244.     }
  245.  
  246.     ::SetCursor(hOC);
  247.  
  248. }
  249.